package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.model.Banner;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.ui.adapter.LoopBannerAdapter;
import com.captainbank.tcl.tclapplication.ui.adapter.TextAdapter;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.wenjian.loopbanner.LoopBanner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by TCL on 2019/6/25.
 * Describe:
 */
public class LoopBannerActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    private List<Banner> bannerList;
    private TextAdapter textAdapter;
    private List<String> textList;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_loop_banner;
    }

    @Override
    protected void initData() {
        textList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            textList.add("我是数据：" + i + 1);
        }

        bannerList = new ArrayList<>();
        Banner banner;
        banner = new Banner();
        banner.setImageUrl("http://test-cloud-wlz-com.oss-cn-shanghai.aliyuncs.com/test/appBANNER%E5%8D%93%E5%BC%95.JPG");
        bannerList.add(banner);
        banner = new Banner();
        banner.setImageUrl("http://test-cloud-wlz-com.oss-cn-shanghai.aliyuncs.com/test/%E6%94%BF%E5%BA%9C%E5%85%A5%E4%BD%8F.JPG");
        bannerList.add(banner);
        banner = new Banner();
        banner.setImageUrl("http://test-cloud-wlz-com.oss-cn-shanghai.aliyuncs.com/test/%E9%A1%B9%E7%9B%AE%E5%AF%B9%E6%8E%A5%E4%BC%9A.jpg");
        bannerList.add(banner);
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_loopbanner));

        //设置Banner
        View headerBanner = getLayoutInflater().inflate(R.layout.header_banner, null);
        LoopBanner lb = headerBanner.findViewById(R.id.loop_banner);
        LoopBannerAdapter loopBannerAdapter= new LoopBannerAdapter(this,bannerList,R.layout.item_loop_banner);
        lb.setAdapter(loopBannerAdapter);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerview.setLayoutManager(layoutManager);
        textAdapter = new TextAdapter(R.layout.item_text, textList);
        recyclerview.setAdapter(textAdapter);
        textAdapter.addHeaderView(headerBanner);
    }
}
